﻿
@{
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listType = ViewBag.Type as List<SGArchiveSystem7x.Models.CComboboxModel>;
}
<table id="ArchiveWord_Index_grid" class="easyui-datagrid" style="width:100%;" title="档案词典" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#ArchiveWord_Index_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
    <thead frozen="true">
        <tr>
            <th field="WD_TYPE" width="100" align="center" formatter="formatType">词典类型</th>
            <th field="WD_NAME" width="100" align="center">词典内容</th>
            <th field="WD_ORDER" width="100" align="center">排序</th>
            <th field="WD_VALUE" width="100" align="center">数值</th>
            <th field="WD_ID" width="100" data-options="align:'center'" formatter="formatEdit">编辑</th>
            <th field="del" width="100" data-options="align:'center'" formatter="formatDel">删除</th>
    </thead>
</table>
<div id="ArchiveWord_Index_tb" style="padding:5px 10px;">
    <b>词典类型：</b>
    <select class="easyui-combobox" labelwidth="30px" style="width:220px" id="ArchiveWord_Index_cmbType" editable="false" panelHeight="auto">
        @{
            foreach (var item in listType)
            {
                <option value="@item.ID">@item.Text</option>
            }
        }
    </select>
    <a href="javascript:void(0);" id="ArchiveWord_Index_btnType" iconCls="icon-add" class="easyui-linkbutton button-blue" onclick="Add_DictionaryType()" style="width:110px;height:30px;">添加词典类型</a>
    <a href="javascript:void(0);" id="ArchiveWord_Index_btnContent" iconCls="icon-add" class="easyui-linkbutton button-blue" onclick="Add_DictionaryContent()" style="width:110px;height:30px;">添加词典内容</a>

</div>

<div id="ArchiveWord_Index_winContent" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-save'" minimizable="false" maximizable="false" resizable="false" collapsible="false"
     style="width:400px;height:280px;padding:10px">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'center'" style="padding:10px;border:0px">
            <div style="padding-top:5px">
                <input class="easyui-textbox" style="width:100%" data-options="required:true,missingMessage:'请输入词典内容！'" label="词典内容：" labelwidth="70px" labelalign="right" id="ArchiveWord_Index_txtName" />
            </div>
            <div style="padding-top:10px">
                <input class="easyui-textbox" style="width:100%" data-options="required:true,missingMessage:'请输入排序内容！'" label="排序：" labelwidth="70px" labelalign="right" id="ArchiveWord_Index_txtOrder" />
            </div>
            <div style="padding-top:10px">
                <input class="easyui-textbox" style="width:100%" label="数值：" labelwidth="70px" labelalign="right" id="ArchiveWord_Index_txtNumber" />
            </div>
            <input type="text" hidden="hidden" id="ArchiveWord_Index_txtId" />
        </div>
        <div data-options="region:'south',border:false" style="text-align:right;padding:0px,0,0;">
            <a class="easyui-linkbutton button-blue" onclick="Save_DictionaryContent()" data-options="iconCls:'icon-ok'" href="javascript:void(0)" style="width:100px">保存</a>
        </div>
    </div>
</div>
<div id="ArchiveWord_Index_winType" class="easyui-window" title="添加词典类型" data-options="modal:true,closed:true,iconCls:'icon-save'" minimizable="false" maximizable="false" resizable="false" collapsible="false"
     style="width:400px;height:200px;padding:10px">
    <div style="padding-top:5px">
        <input class="easyui-textbox" style="width:100%" data-options="required:true,missingMessage:'请输入词典类型！'" label="词典类型：" labelwidth="70px" labelalign="right" id="ArchiveWord_Index_txtTypeName" />
    </div>
    <div data-options="region:'south',border:false" style="text-align:right;padding:0px,0,0;">
        <a class="easyui-linkbutton button-blue" onclick="Save_DictionaryType()" data-options="iconCls:'icon-ok'" href="javascript:void(0)" style="width:100px ;margin-top:50px;">保存</a>
    </div>
</div>
<script>
    var type = '';
    $(document).ready(function () {
        type = $('#ArchiveWord_Index_cmbType').combobox('getValue');
        $('#ArchiveWord_Index_grid').datagrid({
            url: '/ArchiveWord/Get_ajaxDictionaryContent?type=' + type,
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });
    });


    ///初始化分页
    function InitPagenation() {
        //设置分页控件
        var p = $('#ArchiveWord_Index_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                QueryPager(pageNumber, pageSize);
            }
        });
    }

    ///操作之后，把存放数据清除
    function UpdateList() {
        QueryPager($('#ArchiveWord_Index_grid').datagrid('options').pageNumber, $('#ArchiveWord_Index_grid').datagrid('options').pageSize);
    }

    ///分页查询
    function QueryPager(num, size) {
        $('#ArchiveWord_Index_grid').datagrid('options').url = '/ArchiveWord/Get_ajaxDictionaryContentPager?num=' + num + '&size=' + size;
        $('#ArchiveWord_Index_grid').datagrid('reload');
        $('#ArchiveWord_Index_grid').datagrid('options').pageNumber = num;
        $('#ArchiveWord_Index_grid').datagrid('options').pageSize = size;
        return;
    }


    $('#ArchiveWord_Index_cmbType').combobox({
        onChange: function () {
            type = $("#ArchiveWord_Index_cmbType").combotree("getValue");

            $('#ArchiveWord_Index_grid').datagrid({
                url: '/ArchiveWord/Get_ajaxDictionaryContent?type=' + type,
                method: 'post',
                onLoadSuccess: function (data) {
                    $('.pagination-page-list').hide();
                }
            });

        },
    })


    function Edit(id) {
        $.ajax({
            method: 'post',
            dataType: 'json',
            data: { id: id },
            url: '/ArchiveWord/Get_ajaxArchiveWordId',
            success: function (data) {
                    $('#ArchiveWord_Index_txtId').val(data.WD_ID);
                    $("#ArchiveWord_Index_txtName").textbox('setValue', data.WD_NAME);
                    $("#ArchiveWord_Index_txtOrder").textbox('setValue', data.WD_ORDER)
                    $("#ArchiveWord_Index_txtNumber").textbox('setValue', data.WD_VALUE)
                    $('#ArchiveWord_Index_winContent').window({
                        title: '修改词典内容(' + $('#ArchiveWord_Index_cmbType').combobox('getText') + ')',
                        closed: false,
                    });
            }
        })

    }
    //删除
    function Del(id) {
        $.messager.confirm("温馨提示", "确定要删除吗?", function (r) {
            if (r) {
                $.ajax({
                    method: "post",
                    dataType: "text",
                    url: "/ArchiveWord/Del_ajaxArchiveWord",
                    data: { id: id },
                    success: function (data) {
                        if (data == "1") {
                            $.messager.alert("提示","删除成功!","info");
                            UpdateList();
                        } else
                            $.messager.alert("提示","删除失败!","error");
                    }
                })
            }
        })
    }

    function formatEdit(value, row) {
        var id = row["WD_ID"];
        return "<a href = 'javascript:void(0)' onclick='Edit(" + id + ")'><img src='../Content/images/pencil.png' width='16px' height='16px' />&nbsp;修改</a>";
    }
    function formatDel(value, row) {
        var id = row["WD_ID"];
        return "<a href = 'javascript:void(0)' onclick='Del(" + id + ")'><img src='../Content/images/close.png' width='16px' height='16px' />&nbsp;删除</a>";
    }
    function formatType(value, row) {
        value = $('#ArchiveWord_Index_cmbType').combobox('getText');
        return value;
    }

    //添加类型
    function Save_DictionaryType() {
        var TypeName = $('#ArchiveWord_Index_txtTypeName').val();
        if (TypeName == '') {
            $.messager.alert('提示', '类型不能为空!', 'info');
            return;
        }
        $.ajax({
            url: "/ArchiveWord/Get_ajaxArchiveWordType",
            dataType: "text",
            type: "post",
            data: {
                TypeName: TypeName
            },
            success: function (data) {
                if (data == '0')
                    $.messager.alert('提示', '该类型已存在!', 'warning');
                else if (data == '-1')
                    $.messager.alert('提示', '保存失败!', 'error');
                else
                    $.messager.alert('提示', '保存成功!', 'info');
                $('#ArchiveWord_Index_winType').window('close');
                $('#ArchiveWord_Index_cmbType').combobox('clear');//清空
                $('#ArchiveWord_Index_cmbType').combobox({
                    url: '/ArchiveWord/Get_ajaxCom',
                    valueField: 'ID',
                    textField: 'Text'
                }); 
                $('#ArchiveWord_Index_cmbType').combobox('load',);
            }
        });

    }
    //添加内容
    function Save_DictionaryContent() {
        var id = $('#ArchiveWord_Index_txtId').val()
        var Type = $("#ArchiveWord_Index_cmbType").combotree("getValue");
        var Name = $('#ArchiveWord_Index_txtName').val();
        var Order = $('#ArchiveWord_Index_txtOrder').val();
        var Value = $('#ArchiveWord_Index_txtNumber').val();
        var text = $('#ArchiveWord_Index_winContent').panel('options').title;
        if (Name == '') {
            $.messager.alert("提示", "内容不能为空!", "error");
            return;
        }
        if (isNaN(Order)) {
            $.messager.alert("提示", "排序号必须为数字!", "error");
            return;
        }
        if (isNaN(Value)) {
            $.messager.alert("提示", "数值必须为数字!", "error");
            return;
        }
        

        if (text == "添加词典内容(" + $('#ArchiveWord_Index_cmbType').combobox('getText') + ")") {
            $.ajax({
                url: "/ArchiveWord/Get_ajaxAddWord",
                dataType: "text",
                method: "post",
                data: {
                    Name: Name, Order: Order, Type: Type, Value: Value
                },
                success: function (data) {
                    if (data == '0')
                        $.messager.alert('提示', '已存在!', 'warning');
                    else if (data == '-1')
                        $.messager.alert('提示', '保存失败!', 'error');
                    else {
                        $.messager.alert('提示', '保存成功!', 'info');

                        $('#ArchiveWord_Index_txtName').textbox("setValue", "");
                        $('#ArchiveWord_Index_txtOrder').textbox("setValue", "");
                        $('#ArchiveWord_Index_txtNumber').textbox("setValue", "");

                        $('#ArchiveWord_Index_winContent').window('close');
                        $('#ArchiveWord_Index_grid').datagrid('reload');
                    }
                }
            })
        }
        else {
            $.ajax({
                url: "/ArchiveWord/Get_ajaxModifyWord",
                dataType: "text",
                method: "post",
                data: {
                    id: id, Name: Name, Order: Order, Value: Value, type: type
                },
                success: function (data) {
                    if (data == '-1')
                        $.messager.alert('提示', '保存失败!', 'error');
                    else {
                        $.messager.alert('提示', '保存成功!', 'info');

                        $('#ArchiveWord_Index_txtName').textbox("setValue", "");
                        $('#ArchiveWord_Index_txtOrder').textbox("setValue", "");
                        $('#ArchiveWord_Index_txtNumber').textbox("setValue", "");

                        $('#ArchiveWord_Index_winContent').window('close');
                        $('#ArchiveWord_Index_grid').datagrid('reload');   // 重新载入当前页面数据
                    }
                }
            });
        }
    }

    function Add_DictionaryContent() {
        $('#ArchiveWord_Index_winContent').window({
            title: '添加词典内容(' + $('#ArchiveWord_Index_cmbType').combobox('getText') + ')',
            closed: false
        });
    }

    function Add_DictionaryType() {
        $('#ArchiveWord_Index_winType').window({
            closed: false
        });
    }
</script>
